<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
<!--        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>-->
<!--        <el-button type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
<!--      <el-table-column-->
<!--        prop="id"-->
<!--        header-align="center"-->
<!--        align="center"-->
<!--        label="唯一ID">-->
<!--      </el-table-column>-->
<!--      <el-table-column-->
<!--        prop="parentId"-->
<!--        header-align="center"-->
<!--        align="center"-->
<!--        label="父评论id 如果为null 则没有父评论">-->
<!--      </el-table-column>-->
<!--      <el-table-column-->
<!--        prop="backUserId"-->
<!--        header-align="center"-->
<!--        align="center"-->
<!--        label="回复评论用户id 为null则不是回复指定用户">-->
<!--      </el-table-column>-->
      <el-table-column
        prop="content"
        header-align="center"
        align="center"
        label="评论内容">
      </el-table-column>
      <el-table-column
        prop="memberName"
        header-align="center"
        align="center"
        label="评论用户">
      </el-table-column>
<!--      TODO 跳转到对应的话题详情-->
      <el-table-column
        prop="topicId"
        header-align="center"
        align="center"
        label="所在话题">
      </el-table-column>
      <el-table-column
        prop="praiseCount"
        header-align="center"
        align="center"
        label="点赞数">
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="center"
        label="状态">
        <template slot-scope="scope">
          <el-tag  v-if="scope.row.status == 0" size="small" type="danger">禁用</el-tag>
          <el-tag  v-else size="small">正常</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="评论时间">
      </el-table-column>
<!--      <el-table-column-->
<!--        prop="updateTime"-->
<!--        header-align="center"-->
<!--        align="center"-->
<!--        label="修改时间">-->
<!--      </el-table-column>-->
      <el-table-column
        prop="pass"
        header-align="center"
        align="center"
        label="审核状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.pass == 0" size="small" type="danger">未通过</el-tag>
          <el-tag v-if="scope.row.pass == 1" size="small" type="success">通过</el-tag>
          <el-tag v-if="scope.row.pass == 2" size="small" type="warning">审核中</el-tag>
        </template>
      </el-table-column>
<!--      <el-table-column-->
<!--        prop="deleted"-->
<!--        header-align="center"-->
<!--        align="center"-->
<!--        label="是否删除 0删除 1未删除">-->
<!--      </el-table-column>-->
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="disableCommentHandle(scope.row.id,scope.row.status)">
            {{scope.row.status == 1 ? '禁用':'取消禁用'}}
          </el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

  </div>
</template>

<script>

  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        queryObj: {
          pageParams: {
            page: 1,  //当前页
            limit:10,//每页记录数
            sidx: "sort",
            order: "",
          },
          and: {//放在and里面的都是 并且条件
            must:{}, //精确匹配
          }
        }
      }
    },

    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/forum/communitytopiccomment/multiConditList'),
          method: 'post',
          data: this.$http.adornParams(this.queryObj)
        }).then(({data}) => {
          console.log(data)
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.queryObj.pageParams.page =1;
        this.queryObj.pageParams.limit = val;
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.queryObj.pageParams.page = val;
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/forum/communitytopiccomment/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      disableCommentHandle(id,status){
        this.$http({
          url: this.$http.adornUrl(`/forum/communitytopiccomment/${status == 1 ? 'disable' : 'enabled'}/` + id),
          method: 'post',

        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      }
    }
  }
</script>
